
Imports System.Diagnostics.Process
Imports System.Threading

Public Class F_PetMaster
    Dim WithEvents SBO_Application As SAPbouiCOM.Application
    Dim Ocompany As SAPbobsCOM.Company
    Public ShowFolderBrowserThread As Threading.Thread
    Dim strpath As String

    Sub New(ByVal ocompany1 As SAPbobsCOM.Company, ByVal sbo_application1 As SAPbouiCOM.Application)
        SBO_Application = sbo_application1
        Ocompany = ocompany1
    End Sub
    Public Sub PetMaster_bind(ByVal oform As SAPbouiCOM.Form)
        Try
            oform.PaneLevel = 1
            CFL_BP_Customer(oform, SBO_Application)
            oCombo = oform.Items.Item("1000007").Specific
            ComboLoad_Breed(oform, oCombo)
            oEdit = oform.Items.Item("10").Specific
            oEdit.ChooseFromListUID = "CFLBPC"
            oEdit.ChooseFromListAlias = "CardCode"
            oCombo = oform.Items.Item("180").Specific
            ComboLoad_Location(oform, oCombo)
            oform.DataBrowser.BrowseBy = "4"

        Catch ex As Exception
            SBO_Application.StatusBar.SetText(ex.Message, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
        End Try
    End Sub
    Public Sub Boardind_bind_Report(ByVal oform As SAPbouiCOM.Form)
        Try
            CFL_BP_PetMaster(oform, SBO_Application)

            oform.DataSources.UserDataSources.Add("oedit1", SAPbouiCOM.BoDataType.dt_SHORT_TEXT)
            oform.DataSources.UserDataSources.Add("oedit2", SAPbouiCOM.BoDataType.dt_SHORT_TEXT)
            oform.DataSources.UserDataSources.Add("oedit3", SAPbouiCOM.BoDataType.dt_DATE)
            oform.DataSources.UserDataSources.Add("oedit4", SAPbouiCOM.BoDataType.dt_DATE)
            'oform.DataSources.UserDataSources.Add("oedit5", SAPbouiCOM.BoDataType.dt_SHORT_TEXT)
            oEdit = oform.Items.Item("4").Specific
            oEdit.DataBind.SetBound(True, "", "oedit1")
            oEdit.ChooseFromListUID = "CFLPM"
            oEdit.ChooseFromListAlias = "U_PetCode"

            oEdit = oform.Items.Item("6").Specific
            oEdit.DataBind.SetBound(True, "", "oedit3")
            oEdit.String = Format(Now.Date, "dd/MM/yy")
            oEdit = oform.Items.Item("8").Specific
            oEdit.DataBind.SetBound(True, "", "oedit4")
            oEdit.String = Format(Now.Date, "dd/MM/yy")
            'oCombo = oform.Items.Item("12").Specific
            'oCombo.DataBind.SetBound(True, "", "oedit5")
            'oCombo.ValidValues.Add("Pick Up / Drop Off", "PD")
            'oCombo.ValidValues.Add("Pick Up Only", "P")
            'oCombo.ValidValues.Add("Drop Off Only", "D")
            'oCombo.ValidValues.Add("Boarding", "B")

        Catch ex As Exception
            SBO_Application.StatusBar.SetText(ex.Message, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
        End Try
    End Sub

    Public Sub Evaluation_Report_bind_Report(ByVal oform As SAPbouiCOM.Form)
        Try
            CFL_BP_PetMaster(oform, SBO_Application)
            oEdit = oform.Items.Item("4").Specific
            oEdit.ChooseFromListUID = "CFLPM"
            oEdit.ChooseFromListAlias = "U_PetCode"

        Catch ex As Exception
            SBO_Application.StatusBar.SetText(ex.Message, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
        End Try
    End Sub
    Private Sub ComboLoad_Breed(ByRef Oform As SAPbouiCOM.Form, ByRef oCombo As SAPbouiCOM.ComboBox)
        Try
            oRecordSet = Ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
            oRecordSet.DoQuery("SELECT T0.Code, T0.U_Name FROM [dbo].[@AI_BREED]  T0")
            Dim it As Integer = 1
            For it = oCombo.ValidValues.Count - 1 To 0 Step -1
                oCombo.ValidValues.Remove(it, SAPbouiCOM.BoSearchKey.psk_Index)
            Next
            Do While Not oRecordSet.EoF
                oCombo.ValidValues.Add(oRecordSet.Fields.Item(1).Value, oRecordSet.Fields.Item(0).Value)
                oRecordSet.MoveNext()
            Loop
            oRecordSet = Nothing
            GC.Collect()
        Catch ex As Exception
            SBO_Application.StatusBar.SetText(ex.Message, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
        End Try
    End Sub
    Private Sub ComboLoad_Location(ByRef Oform As SAPbouiCOM.Form, ByRef oCombo As SAPbouiCOM.ComboBox)
        Try
            oRecordSet = Ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
            oRecordSet.DoQuery("SELECT T0.Code, T0.Name FROM [dbo].[@AI_LOCATION]  T0")
            Dim it As Integer = 1
            For it = oCombo.ValidValues.Count - 1 To 0 Step -1
                oCombo.ValidValues.Remove(it, SAPbouiCOM.BoSearchKey.psk_Index)
            Next
            Do While Not oRecordSet.EoF
                oCombo.ValidValues.Add(oRecordSet.Fields.Item(1).Value, oRecordSet.Fields.Item(0).Value)
                oRecordSet.MoveNext()
            Loop
            oRecordSet = Nothing
            GC.Collect()
        Catch ex As Exception
            SBO_Application.StatusBar.SetText(ex.Message, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
        End Try
    End Sub
    'Public Sub ShowFolderBrowser()
    '    ' Try
    '    Dim MyTest As New OpenFileDialog
    '    Dim MyProcs() As Process
    '    MyProcs = Process.GetProcessesByName("SAP Business One")
    '    Dim i As Integer = 0
    '    If MyProcs.Length >= 1 Then
    '        'For i As Integer = 0 To MyProcs.Length - 1
    '        Dim MyWindow As New WindowWrapper(MyProcs(i).MainWindowHandle)
    '        MyTest.InitialDirectory = "C:\"
    '        MyTest.Filter = "All files (*.xlsx)|*.xlsx|All files (*.xlsx)|*.xlsx"
    '        'MyTest.ShowDialog(MyWindow)

    '        If MyTest.ShowDialog(MyWindow) = DialogResult.OK Then
    '            strpath = MyTest.FileName
    '            'ShowFolderBrowserThread.Abort()
    '        Else
    '            'ShowFolderBrowserThread.Abort()
    '        End If

    '        ' Next
    '    Else
    '        SBO_Application.MessageBox("No SBO instances found.")
    '        'ShowFolderBrowserThread.Abort()
    '    End If
    '    ShowFolderBrowserThread.Abort()
    '    'Catch ex As Exception
    '    '    SBO_Application.MessageBox(ex.Message)
    '    '    ShowFolderBrowserThread.Abort()
    '    'End Try
    'End Sub
    Public Sub Loadfile(ByVal FileName As String)
        Try
            Dim p As New System.Diagnostics.Process
            Dim s As New System.Diagnostics.ProcessStartInfo(FileName)
            s.UseShellExecute = True
            s.WindowStyle = ProcessWindowStyle.Normal
            p.StartInfo = s
            p.Start()

        Catch ex As Exception
            SBO_Application.StatusBar.SetText(ex.Message, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
            'SBO_Application.StatusBar.SetText("Path Name Is Empty!", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
        End Try
    End Sub
    Private Sub SBO_Application_ItemEvent(ByVal FormUID As String, ByRef pVal As SAPbouiCOM.ItemEvent, ByRef BubbleEvent As Boolean) Handles SBO_Application.ItemEvent
        Try

            If pVal.FormUID = "AI_PETMASTER" And pVal.ItemUID = "188" And pVal.Before_Action = True And pVal.EventType = SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED Then
                Dim trd As Thread
                trd = New Thread(AddressOf EValation)
                trd.IsBackground = True
                trd.SetApartmentState(ApartmentState.STA)
                trd.Start()
            End If

            If pVal.FormUID = "Evaluation_Report" And pVal.ItemUID = "Print" And pVal.Before_Action = True And pVal.EventType = SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED Then
                Dim trd As Thread
                trd = New Thread(AddressOf EValation)
                trd.IsBackground = True
                trd.SetApartmentState(ApartmentState.STA)
                trd.Start()
            End If

            If pVal.FormUID = "AI_PETMASTER" And pVal.ItemUID = "195" And pVal.Before_Action = True And pVal.EventType = SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED Then
                Dim trd As Thread
                trd = New Thread(AddressOf CustomerRegisrtation)
                trd.IsBackground = True
                trd.SetApartmentState(ApartmentState.STA)
                trd.Start()
            End If

            If pVal.FormUID = "AI_PETMASTER" And pVal.ItemUID = "19" And pVal.Before_Action = False And pVal.EventType = SAPbouiCOM.BoEventTypes.et_DOUBLE_CLICK Then
                oForm = SBO_Application.Forms.Item("AI_PETMASTER")
                oPict = oForm.Items.Item("19").Specific
                Dim st As String = oPict.Picture
                If oEdit.String <> "" Then
                    Loadfile(st)

                End If
            End If
            If ((pVal.FormUID = "AI_PETMASTER" And pVal.ItemUID = "Op" And pVal.EventType = SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED) And (pVal.Before_Action = False)) Then
                oForm = SBO_Application.Forms.Item("AI_PETMASTER")
                oEdit = oForm.Items.Item("182").Specific
                Dim st As String = oEdit.String
                If oEdit.String <> "" Then
                    Loadfile(st)
                Else

                    SBO_Application.StatusBar.SetText("File Path Can't Be Empty!", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
                    Exit Sub
                End If
            End If
            If ((pVal.FormUID = "AI_PETMASTER" And pVal.ItemUID = "Br" And pVal.EventType = SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED) And (pVal.Before_Action = False)) Then
                Try
                    oForm = SBO_Application.Forms.Item("AI_PETMASTER")

                    ShowFolderBrowserThread = New Threading.Thread(AddressOf ShowFolderBrowser)
                    If ShowFolderBrowserThread.ThreadState = Threading.ThreadState.Unstarted Then
                        ShowFolderBrowserThread.SetApartmentState(Threading.ApartmentState.STA)
                        ShowFolderBrowserThread.Start()
                        ShowFolderBrowserThread.Join()
                    Else
                        ShowFolderBrowserThread.Abort()
                    End If
                    'If pVal.ItemUID = "Button1" And pVal.EventType = SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED Then
                    oEdit = oForm.Items.Item("182").Specific
                    oEdit.String = strpath
                    ShowFolderBrowserThread.Abort()
                    'End If
                Catch ex As Exception

                End Try

            End If

            'Choose From List
            Try
                If pVal.FormUID = "Evaluation_Report" Then
                    oForm = SBO_Application.Forms.Item("Evaluation_Report")
                    If pVal.EventType = SAPbouiCOM.BoEventTypes.et_CHOOSE_FROM_LIST Then
                        Dim oCFLEvento As SAPbouiCOM.IChooseFromListEvent
                        oCFLEvento = pVal
                        Dim sCFL_ID As String
                        sCFL_ID = oCFLEvento.ChooseFromListUID
                        oForm = SBO_Application.Forms.Item(FormUID)
                        Dim oCFL As SAPbouiCOM.ChooseFromList
                        oCFL = oForm.ChooseFromLists.Item(sCFL_ID)
                        Try
                            If oCFLEvento.BeforeAction = False Then
                                Dim oDataTable As SAPbouiCOM.DataTable
                                oDataTable = oCFLEvento.SelectedObjects
                                If pVal.ItemUID = "4" Then
                                    oEdit = oForm.Items.Item("4").Specific
                                    oEdit.String = oDataTable.GetValue("U_PetCode", 0)
                                End If
                            End If
                        Catch ex As Exception
                            '' SBO_Application.StatusBar.SetText(ex.Message, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
                        End Try
                    End If
                End If
                '--------------------
            Catch ex As Exception

            End Try
            'Choose From List
            Try
                If pVal.FormUID = "AI_PETMASTER" Then
                    oForm = SBO_Application.Forms.Item("AI_PETMASTER")
                    If pVal.EventType = SAPbouiCOM.BoEventTypes.et_CHOOSE_FROM_LIST Then
                        Dim oCFLEvento As SAPbouiCOM.IChooseFromListEvent
                        oCFLEvento = pVal
                        Dim sCFL_ID As String
                        sCFL_ID = oCFLEvento.ChooseFromListUID
                        oForm = SBO_Application.Forms.Item(FormUID)
                        Dim oCFL As SAPbouiCOM.ChooseFromList
                        oCFL = oForm.ChooseFromLists.Item(sCFL_ID)
                        Try
                            If oCFLEvento.BeforeAction = False Then
                                Dim oDataTable As SAPbouiCOM.DataTable
                                oDataTable = oCFLEvento.SelectedObjects
                                If pVal.ItemUID = "10" Then
                                    oEdit = oForm.Items.Item("12").Specific
                                    oEdit.String = oDataTable.GetValue("CardName", 0)
                                    oEdit = oForm.Items.Item("14").Specific
                                    oEdit.String = oDataTable.GetValue("Phone1", 0)
                                    oEdit = oForm.Items.Item("16").Specific
                                    oEdit.String = oDataTable.GetValue("Phone2", 0)
                                    oEdit = oForm.Items.Item("18").Specific
                                    oEdit.String = oDataTable.GetValue("Cellular", 0)
                                    Dim BPCode As String = oDataTable.GetValue("CardCode", 0)

                                    oRecordSet1 = Ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
                                    oRecordSet1.DoQuery("SELECT T0.[Address] ,T0.[Block],T0.[Building],T1.[Name],T0.[Territory]  FROM [dbo].[OCRD]  T0 INNER JOIN OCRY T1 ON T0.Country = T1.Code WHERE T0.[CardCode] ='" & BPCode & "'")
                                    Dim BPAddr As String = oRecordSet1.Fields.Item(0).Value & "  " & oRecordSet1.Fields.Item(1).Value & "  " & oRecordSet1.Fields.Item(2).Value & "  " & oRecordSet1.Fields.Item(3).Value
                                    oEdit = oForm.Items.Item("176").Specific
                                    oEdit.String = BPAddr
                                    oRecordSet = Ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
                                    oRecordSet.DoQuery("SELECT T0.[U_AI_CustCode] FROM [dbo].[@AI_PETMASTER]  T0 WHERE T0.[U_AI_CustCode] ='" & BPCode & "'")
                                    oEdit = oForm.Items.Item("4").Specific
                                    oEdit.String = PetCode(oRecordSet.RecordCount, BPCode)
                                    oRecordSet = Nothing
                                    GC.Collect()
                                    oEdit = oForm.Items.Item("10").Specific
                                    oEdit.String = oDataTable.GetValue("CardCode", 0)
                                End If
                            End If
                        Catch ex As Exception
                            '' SBO_Application.StatusBar.SetText(ex.Message, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
                        End Try
                    End If
                End If
                '--------------------
            Catch ex As Exception

            End Try
            '-------------------End Choose From List-----------
            If pVal.FormUID = "AI_PETMASTER" And pVal.InnerEvent = False Then
                oForm = SBO_Application.Forms.Item("AI_PETMASTER")
                If pVal.Before_Action = False Then
                    Select Case pVal.EventType
                        Case SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED
                            If pVal.ItemUID = "21" Then
                                oForm.PaneLevel = 1
                            ElseIf pVal.ItemUID = "78" Then
                                oForm.PaneLevel = 2
                            ElseIf pVal.ItemUID = "127" Then
                                oForm.PaneLevel = 3
                            ElseIf pVal.ItemUID = "148" Then
                                oForm.PaneLevel = 4
                            ElseIf pVal.ItemUID = "152" Then
                                oForm.PaneLevel = 5
                            ElseIf pVal.ItemUID = "20" Then
                                Try
                                    oForm = SBO_Application.Forms.Item("AI_PETMASTER")
                                    ShowFolderBrowserThread = New Threading.Thread(AddressOf ShowFolderBrowser)
                                    If ShowFolderBrowserThread.ThreadState = Threading.ThreadState.Unstarted Then
                                        ShowFolderBrowserThread.SetApartmentState(Threading.ApartmentState.STA)
                                        ShowFolderBrowserThread.Start()
                                        ShowFolderBrowserThread.Join()
                                    Else
                                        ShowFolderBrowserThread.Abort()
                                    End If
                                    'If pVal.ItemUID = "Button1" And pVal.EventType = SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED Then
                                    oPict = oForm.Items.Item("19").Specific
                                    oPict.Picture = strpath
                                    ShowFolderBrowserThread.Abort()
                                    'End If
                                Catch ex As Exception

                                End Try
                            End If
                    End Select
                    '--------------Befor Event True-----------
                ElseIf pVal.Before_Action = True Then
                    Select Case pVal.EventType
                        Case SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED
                            If pVal.FormMode = SAPbouiCOM.BoFormMode.fm_UPDATE_MODE Or pVal.FormMode = SAPbouiCOM.BoFormMode.fm_ADD_MODE Then
                                If pVal.ItemUID = "1" Then
                                    oEdit = oForm.Items.Item("10").Specific
                                    If oEdit.String = "" Then
                                        SBO_Application.StatusBar.SetText("Select BP/Owner Code", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
                                        BubbleEvent = False
                                        Exit Sub
                                    End If
                                    oEdit = oForm.Items.Item("4").Specific
                                    If oEdit.String = "" Then
                                        SBO_Application.StatusBar.SetText("Select Pet Code", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
                                        BubbleEvent = False
                                        Exit Sub
                                    End If
                                    Dim pcode As String = oEdit.String
                                    oRecordSet = Ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
                                    oRecordSet.DoQuery("SELECT T0.[U_PetCode] FROM [dbo].[@AI_PETMASTER]  T0 WHERE T0.[U_PetCode] ='" & pcode & "'")
                                    If oRecordSet.RecordCount > 0 And pVal.FormMode = SAPbouiCOM.BoFormMode.fm_ADD_MODE Then
                                        SBO_Application.StatusBar.SetText("This Pet Code Already in DataBase. Select Different Pet Code", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
                                        BubbleEvent = False
                                        Exit Sub
                                    End If
                                End If
                            End If
                    End Select
                End If
            End If



        Catch ex As Exception
            'SBO_Application.StatusBar.SetText(ex.Message, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
        End Try
    End Sub
    Private Sub EValation()
        oForm = SBO_Application.Forms.Item("Evaluation_Report")
        Dim Sqlstr As String = ""
        Dim PetCode As String = ""
        oEdit = oForm.Items.Item("4").Specific
        If oEdit.String = "" Then
            SBO_Application.StatusBar.SetText("Pet Code Can't Be Empty!", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
            Exit Sub
        Else
            PetCode = oEdit.String
        End If
        Dim eveldt As String = ""
        oEdit = oForm.Items.Item("ER6").Specific
        If oEdit.String = "" Then
            SBO_Application.StatusBar.SetText("Evaluation Date Can't Be Empty!", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
            Exit Sub
        Else
            eveldt = oEdit.Value
        End If
        Try

            SBO_Application.StatusBar.SetText("Retrieving Data", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Success)
            Sqlstr = "SELECT T0.[U_ADULPUPP], T0.[U_PetCode] FROM [dbo].[@AI_EVALUATION]  T0 WHERE T0.[U_PetCode] ='" & PetCode & "' and T0.CreateDate='" & eveldt & "'"
            oRecordSet = Ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
            oRecordSet.DoQuery(Sqlstr)

            If oRecordSet.RecordCount = 0 Then
                SBO_Application.StatusBar.SetText("No Data Found!", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
                Exit Sub
            End If
            oRecordSet.MoveLast()
            Sqlstr = ""
            If oRecordSet.Fields.Item(0).Value = "adult" Then
                Sqlstr = "SELECT T0.U_HName, T0.U_PetName, T0.U_PetCode, T0.U_OName, T0.U_ADULPUPP, T0.U_HandName, T0.U_OwnerName, T0.U_AdultOrPuppy, T0.U_R1, T0.U_I1, T0.U_S1, T0.U_A1, T0.U_R2, T0.U_I2, T0.U_S2, T0.U_A2, T0.U_R31, T0.U_R32, T0.U_I31, T0.U_I32, T0.U_S31, T0.U_S32, T0.U_A31, T0.U_A32, T0.U_R41, T0.U_R42, T0.U_I41, T0.U_I42, T0.U_S41, T0.U_S42, T0.U_A41, T0.U_A42, T0.U_R5, T0.U_I5, T0.U_S5, T0.U_A5, T0.U_R61, T0.U_R62, T0.U_R63, T0.U_R64, T0.U_R65, T0.U_I61, T0.U_I62, T0.U_I63, T0.U_I64, T0.U_I65, T0.U_S61, T0.U_S62, T0.U_S63, T0.U_S64, T0.U_S65, T0.U_A61, T0.U_A62, T0.U_A63, T0.U_A64, T0.U_A65, T0.U_R71, T0.U_R72, T0.U_I71, T0.U_I72, T0.U_S71, T0.U_S72, T0.U_A71, T0.U_A72, T0.U_TPR, T0.U_TPI, T0.U_TPS, T0.U_TPA,T0.[U_ASEC1], T0.[U_ASEC2], T0.[U_ASEC3], T0.[U_ASEC4], T0.[U_ASEC5], T0.[U_ASEC6], T0.[U_ASEC7]  FROM [dbo].[@AI_EVALUATION]  T0 WHERE T0.[U_PetCode] ='" & PetCode & "' and T0.CreateDate='" & eveldt & "'"
                Dim frm As MY_Report
                frm = New MY_Report
                frm.Evaluation_Adult_Report(Sqlstr, Ocompany)
                frm.Text = "Evaluation Report"
                frm.TopMost = True
                frm.Activate()
                frm.ShowDialog()
                frm.Show()


            ElseIf oRecordSet.Fields.Item(0).Value = "Puppy" Then
                Sqlstr = "SELECT T0.U_HName, T0.U_PetName, T0.U_PetCode, T0.U_OName, T0.U_ADULPUPP, T0.U_HandName, T0.U_OwnerName, T0.U_AdultOrPuppy,T0.U_PR11, T0.U_PR12, T0.U_PI11, T0.U_PI12, T0.U_PS11, T0.U_PS12, T0.U_PA11, T0.U_PA12, T0.U_PR2, T0.U_PI2, T0.U_PS2, T0.U_PA2, T0.U_PR31, T0.U_PR32, T0.U_PR33, T0.U_PR34, T0.U_PR35, T0.U_PI31, T0.U_PI32, T0.U_PI33, T0.U_PI34, T0.U_PI35, T0.U_PS31, T0.U_PS32, T0.U_PS33, T0.U_PS34, T0.U_PS35, T0.U_PA31, T0.U_PA32, T0.U_PA33, T0.U_PA34, T0.U_PA35, T0.U_PR41, T0.U_PR42, T0.U_PI41, T0.U_PI42, T0.U_PS41, T0.U_PS42, T0.U_PA41, T0.U_PA42, T0.U_PR51, T0.U_PR52, T0.U_PR53, T0.U_PR54, T0.U_PR55, T0.U_PI51, T0.U_PI52, T0.U_PI53, T0.U_PI54, T0.U_PI55, T0.U_PS51, T0.U_PS52, T0.U_PS53, T0.U_PS54, T0.U_PS55, T0.U_PA51, T0.U_PA52, T0.U_PA53, T0.U_PA54, T0.U_PA55, T0.U_PR61, T0.U_PR62, T0.U_PI61, T0.U_PI62, T0.U_PS61, T0.U_PS62, T0.U_PA61, T0.U_PA62, T0.U_PTPR, T0.U_PTPI, T0.U_PTPS, T0.U_PTPA,T0.[U_PSEC1], T0.[U_PSEC2], T0.[U_PSEC3], T0.[U_PSEC4], T0.[U_PSEC5], T0.[U_PSEC6]  FROM [dbo].[@AI_EVALUATION]  T0 WHERE T0.[U_PetCode] ='" & PetCode & "' and T0.CreateDate='" & eveldt & "'"
                Dim frm As MY_Report
                frm = New MY_Report
                frm.Evaluation_Puppy_Report(Sqlstr, Ocompany)
                frm.Text = "Evaluation Report"
                frm.TopMost = True
                frm.Activate()
                frm.ShowDialog()
            Else
                Exit Sub
            End If


        Catch ex As Exception
        End Try
    End Sub

    Private Sub CustomerRegisrtation()
        Try
            oForm = SBO_Application.Forms.Item("AI_PETMASTER")
            Dim Sqlstr As String = ""

            Dim PetCode As String = ""
            oEdit = oForm.Items.Item("4").Specific
            If oEdit.String = "" Then
                SBO_Application.StatusBar.SetText("Pet Code Can't Be Empty!", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
                Exit Sub
            Else
                PetCode = oEdit.String
            End If
            Sqlstr = "SELECT [Petcode] FROM [CustSignature] where Petcode='" & PetCode & "'"
            oRecordSet = Ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
            oRecordSet.DoQuery(Sqlstr)
            If oRecordSet.RecordCount = 0 Then
                SBO_Application.StatusBar.SetText("No Data Found!", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
                Exit Sub
            End If
            SBO_Application.StatusBar.SetText("Retrieving Data", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Success)

            Dim cryRpt As New CrystalDecisions.CrystalReports.Engine.ReportDocument
            Dim crtableLogoninfos As New CrystalDecisions.Shared.TableLogOnInfos
            Dim crtableLogoninfo As New CrystalDecisions.Shared.TableLogOnInfo
            Dim crConnectionInfo As New CrystalDecisions.Shared.ConnectionInfo
            Dim CrTables As CrystalDecisions.CrystalReports.Engine.Tables
            Dim CrTable As CrystalDecisions.CrystalReports.Engine.Table

            Dim sPath As String
            sPath = IO.Directory.GetParent(Application.StartupPath).ToString

            'MsgBox(System.Windows.Forms.Application.StartupPath.ToString)
            cryRpt.Load(sPath & "\K9\Customer Registration Report.rpt")
            'cryRpt.Load("PUT CRYSTAL REPORT PATH HERE\CrystalReport1.rpt")

            Dim crParameterFieldDefinitions As CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinitions
            Dim crParameterFieldDefinition As CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinition
            Dim crParameterValues As New CrystalDecisions.Shared.ParameterValues
            Dim crParameterDiscreteValue As New CrystalDecisions.Shared.ParameterDiscreteValue

            crParameterDiscreteValue.Value = PetCode 'Convert.ToInt32(DocNum)
            crParameterFieldDefinitions = _
        cryRpt.DataDefinition.ParameterFields
            crParameterFieldDefinition = _
        crParameterFieldDefinitions.Item("@PetCode")
            crParameterValues = crParameterFieldDefinition.CurrentValues

            crParameterValues.Clear()
            crParameterValues.Add(crParameterDiscreteValue)
            crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)
            Dim Server As String = Ocompany.Server
            Dim DB As String = Ocompany.CompanyDB
            Dim file As System.IO.StreamReader = New System.IO.StreamReader(sPath & "\K9\" & "Pwd.txt", True)
            Dim pwd As String
            pwd = file.ReadLine()

            With crConnectionInfo
                .ServerName = Server
                .DatabaseName = DB
                .UserID = "sa"
                .Password = pwd
            End With

            CrTables = cryRpt.Database.Tables
            For Each CrTable In CrTables
                crtableLogoninfo = CrTable.LogOnInfo
                crtableLogoninfo.ConnectionInfo = crConnectionInfo
                CrTable.ApplyLogOnInfo(crtableLogoninfo)
            Next


            Dim RptFrm As MY_Report
            RptFrm = New MY_Report
            RptFrm.CrystalReportViewer1.ReportSource = cryRpt
            RptFrm.CrystalReportViewer1.Refresh()
            RptFrm.Text = "Customer Regisrtation Report"
            RptFrm.TopMost = True

            RptFrm.Activate()
            RptFrm.ShowDialog()

        Catch ex As Exception
            SBO_Application.StatusBar.SetText(ex.Message, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
        End Try
    End Sub
    Private Sub CustomerRegisrtation1()
        oForm = SBO_Application.Forms.Item("AI_PETMASTER")
        Dim Sqlstr As String = ""
        SBO_Application.StatusBar.SetText("Retrieving Data", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Success)
        Dim PetCode As String = ""
        oEdit = oForm.Items.Item("4").Specific
        If oEdit.String = "" Then
            SBO_Application.StatusBar.SetText("Pet Code Can't Be Empty!", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
            Exit Sub
        Else
            PetCode = oEdit.String
        End If
        Try
            SBO_Application.StatusBar.SetText("Retrieving Data", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Success)
            'SBO_Application.StatusBar.SetText("report is generating")
            Dim cryRpt As New CrystalDecisions.CrystalReports.Engine.ReportDocument
            Dim ERRPT As New CrystalDecisions.CrystalReports.Engine.ReportDocument
            Dim objConInfo As New CrystalDecisions.Shared.ConnectionInfo
            Dim oLogonInfo As New CrystalDecisions.Shared.TableLogOnInfo
            Dim ConInfo As New CrystalDecisions.Shared.TableLogOnInfo
            Dim intCounter As Integer
            '  Dim Formula As String
            Dim OneMore As Boolean = False
            Dim sPath As String
            sPath = IO.Directory.GetParent(Application.StartupPath).ToString
            'MsgBox(System.Windows.Forms.Application.StartupPath.ToString)
            cryRpt.Load(sPath & "\GK_FM\AB_RP004_DO.rpt")
            ' cryRpt.RecordSelectionFormula = "{SP_AI_DeliveryOrder;1.DocEntry} ='" & oEdit.Value.ToString & "'"
            Dim ParaName As String = "@DocKey"
            Dim ParaValue As String = oEdit.Value
            Dim pvCollection As New CrystalDecisions.Shared.ParameterValues
            Dim Para As New CrystalDecisions.Shared.ParameterDiscreteValue
            Dim MyArr1 As Array = ParaName.Split(";")
            Dim MyArr2 As Array = ParaValue.Split(";")
            For i As Integer = 0 To MyArr1.Length - 1
                Para.Value = MyArr2(i)
                pvCollection.Add(Para)
                cryRpt.DataDefinition.ParameterFields(MyArr1(i)).ApplyCurrentValues(pvCollection)
            Next
            Dim file As System.IO.StreamReader = New System.IO.StreamReader(sPath & "\K9\" & "Pwd.txt", True)
            Dim pwd As String = ""
            pwd = file.ReadLine()
            ConInfo.ConnectionInfo.UserID = "sa"
            ConInfo.ConnectionInfo.Password = pwd
            ConInfo.ConnectionInfo.ServerName = Ocompany.Server
            ConInfo.ConnectionInfo.DatabaseName = Ocompany.CompanyDB
            For intCounter = 0 To cryRpt.Database.Tables.Count - 1
                cryRpt.Database.Tables(intCounter).ApplyLogOnInfo(ConInfo)
            Next
            Dim RptFrm As MY_Report
            RptFrm = New MY_Report
            RptFrm.CrystalReportViewer1.ReportSource = cryRpt
            RptFrm.Refresh()
            RptFrm.Text = "Delivery Order Report"
            RptFrm.TopMost = True
            RptFrm.Activate()
            RptFrm.ShowDialog()
            RptFrm.Refresh()
            '
            'Sqlstr = "SELECT T0.[PetCode] FROM [dbo].[CustSignature]  T0 WHERE T0.[PetCode] ='" & PetCode & "'"
            'oRecordSet = Ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
            'oRecordSet.DoQuery(Sqlstr)
            'If oRecordSet.RecordCount = 0 Then
            '    SBO_Application.StatusBar.SetText("No Data Found!", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
            '    Exit Sub
            'End If

            'Sqlstr = "select PetCode,[PetName],[Ccode],[CName],[Addr],cast([Sig] from CustSignature where petcode='" & PetCode & "'"
            'Dim frm As MY_Report
            'frm = New MY_Report
            'frm.CustSig(Sqlstr, Ocompany)
            'frm.Text = "Customer Registration Report"
            'frm.TopMost = True
            'frm.Activate()
            'frm.ShowDialog()
            'frm.Show()



        Catch ex As Exception
        End Try
    End Sub
    Public Function PetCode(ByVal a As Integer, ByVal BpCode As String) As String
        Dim x As String = ""
        Select Case a
            Case "0"
                x = BpCode & "A"
                Exit Select
            Case "1"
                x = BpCode & "B"
                Exit Select
            Case "2"
                x = BpCode & "C"
                Exit Select
            Case "3"
                x = BpCode & "D"
                Exit Select
            Case "4"
                x = BpCode & "E"
                Exit Select
            Case "5"
                x = BpCode & "F"
                Exit Select
            Case "6"
                x = BpCode & "G"
                Exit Select
            Case "7"
                x = BpCode & "H"
                Exit Select
            Case "8"
                x = BpCode & "I"
                Exit Select
            Case "9"
                x = BpCode & "J"
                Exit Select
            Case "10"
                x = BpCode & "K"
                Exit Select
            Case "11"
                x = BpCode & "L"
                Exit Select
            Case "12"
                x = BpCode & "M"
                Exit Select
            Case "13"
                x = BpCode & "N"
                Exit Select
            Case "14"
                x = BpCode & "O"
                Exit Select
            Case "15"
                x = BpCode & "P"
                Exit Select
            Case "16"
                x = BpCode & "Q"
                Exit Select
            Case "17"
                x = BpCode & "R"
                Exit Select
            Case "18"
                x = BpCode & "S"
                Exit Select
            Case "19"
                x = BpCode & "T"
                Exit Select
            Case "20"
                x = BpCode & "U"
                Exit Select
            Case "21"
                x = BpCode & "V"
                Exit Select
            Case "22"
                x = BpCode & "W"
                Exit Select
            Case "23"
                x = BpCode & "X"
                Exit Select
            Case "24"
                x = BpCode & "Y"
                Exit Select
            Case "25"
                x = BpCode & "Z"
                Exit Select
            Case Else
                x = BpCode
                Exit Select
        End Select
        Return x
    End Function
    Public Sub ShowFolderBrowser()
        ' Try
        Dim MyTest As New OpenFileDialog
        Dim MyProcs() As Process
        MyProcs = Process.GetProcessesByName("SAP Business One")
        Dim i As Integer = 0
        If MyProcs.Length >= 1 Then
            'For i As Integer = 0 To MyProcs.Length - 1
            Dim MyWindow As New WindowWrapper(MyProcs(i).MainWindowHandle)
            MyTest.InitialDirectory = "C:\"
            MyTest.Filter = "All files (*.*)|*.*|All files (*.*)|*.*"
            'MyTest.ShowDialog(MyWindow)

            If MyTest.ShowDialog(MyWindow) = DialogResult.OK Then
                strpath = MyTest.FileName
                'ShowFolderBrowserThread.Abort()
            Else
                'ShowFolderBrowserThread.Abort()
            End If

            ' Next
        Else
            SBO_Application.MessageBox("No SBO instances found.")
            'ShowFolderBrowserThread.Abort()
        End If
        ShowFolderBrowserThread.Abort()
        'Catch ex As Exception
        '    SBO_Application.MessageBox(ex.Message)
        '    ShowFolderBrowserThread.Abort()
        'End Try
    End Sub
End Class
